package org.jetlinks.pro.equipment.web;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.hswebframework.web.authorization.annotation.Resource;
import org.hswebframework.web.crud.service.ReactiveCrudService;
import org.jetlinks.pro.equipment.Services.EquipmentService;
import org.jetlinks.pro.equipment.entity.EquipmentEntity;
import org.jetlinks.pro.equipment.tenant.EquipmentAssertType;
import org.jetlinks.pro.tenant.AssetType;
import org.jetlinks.pro.tenant.crud.TenantCorrelatesAccessCrudController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Nonnull;
import java.util.function.Function;

@RestController
@RequestMapping("/equipment")
@Tag(name = "设备管理")
@Resource(id = "equipment-manager", name = "设备管理")
public class EquipmentController implements TenantCorrelatesAccessCrudController<EquipmentEntity, String> {

    private final EquipmentService equipmentService;

    public EquipmentController(EquipmentService equipmentService) {
        this.equipmentService = equipmentService;
    }

    @Override
    public EquipmentService getService() {
        return equipmentService;
    }

    @Nonnull
    @Override
    public AssetType getAssetType() {
        return EquipmentAssertType.equipment;
    }

    @Nonnull
    @Override
    public Function<EquipmentEntity, ?> getAssetIdMapper() {
        return EquipmentEntity::getId;
    }

    @Nonnull
    @Override
    public String getAssetProperty() {
        return "equipment";
    }
}
